<template>
    <el-dialog v-model="dialogFormVisible" :title="title" @close="closeDialog">
        <el-form :model="editclassTeacherForm" ref="editClassScheduleRef" :rules="editScheduleRules">
            <el-form-item label="班级" :label-width="formLabelWidth" style="margin-left: 10px">
                <el-input
                        v-model="classTeacherForm.className" autocomplete="off" readonly style="width: 218px"
                ></el-input>
            </el-form-item>
            <el-form-item label="科目" :label-width="formLabelWidth" style="margin-left: 10px">
                <el-input
                        v-model="classTeacherForm.subject" autocomplete="off" readonly style="width: 218px"
                ></el-input>
            </el-form-item>
            <el-form-item label="人员" :label-width="formLabelWidth"
                          prop="teacherNumber">
                <el-radio-group v-model="classTeacherForm.teacherNumber" class="ml-4">
                    <el-radio v-for="item in teacherList" :label="item.teacherNumber" style="width: 100px">{{item.teacherName}}</el-radio>
                    <el-radio label="空" style="width: 100px">无</el-radio>
                </el-radio-group>
            </el-form-item>
        </el-form>
        <template #footer>
            <span class="dialog-footer">
                <el-button @click="cancel()">取消</el-button>
                <el-button type="primary" @click="save()">保存</el-button>
            </span>
        </template>
    </el-dialog>
</template>

<script>
    import {ref} from "vue";
    import {httpService} from "@/utils/httpService";
    import {ElMessage, ElForm} from "element-plus";
    import {vxRule} from "@/utils/validator";

    export default {
        name: "teacher",
        components: {ElForm, ElMessage},
        data() {
            return {
                dialogFormVisible: ref(false),
                teacherList: [],
                classTeacherForm: {
                    campus: "",
                    className: "",
                    subject: "",
                    teacherNumber: "",
                    teacherName: "",
                },
                // 校验规则
                editScheduleRules: {
                    className: vxRule(true, null, "blur"),
                    teacherNumber: vxRule(true, null, "blur"),
                },
            };
        },
        mounted() {
        },
        methods: {
            closeDialog() {
                this.clear();
            },
            cancel() {
                this.dialogFormVisible = false;
                this.clear();
            },
            getTeacherSubjectList() {
                httpService(
                    "/pythonApi/scheduleApi/getTeacherSubjectList",
                    {
                        page:1,
                        limit:1000,
                        subject: this.classTeacherForm.subject
                    },
                    "get"
                ).then((data) => {
                    this.teacherList = data.data;
                });
            },
            clear() {
                this.dialogFormVisible = false;
                //清空form
                    this.classTeacherForm.teacherNumber = "";
                    this.classTeacherForm.teacherName = "";
                    this.classTeacherForm.departmentName = "";

            },
            save() {
                let params = new FormData(); //创建一个form对象,必须是form对象否则后端接受不到数据
                params.append("className", this.classTeacherForm.className);
                params.append("subject", this.classTeacherForm.subject);
                params.append("teacherNumber", this.classTeacherForm.teacherNumber);
                httpService("/pythonApi/scheduleApi/changeClassSubjectTeacher", params, "post").then(
                    (data) => {
                        if (data.code == 200) {
                            ElMessage.success(data.message);
                            this.clear();
                            //刷新父组件的数据
                            this.$parent.getClassTeacherList();
                        } else {
                            ElMessage.error(data.message);
                        }
                    }
                );
            },
        },
    };
</script>
<style>
</style>